@extends('layouts.admin')
@section('content')

    <!--Side menu and right menu -->

    <!-- main content -->
    <section class="content home">
        <div class="container-fluid">
            <div class="block-header">
                <h2>内容管理</h2>
                <ol class="breadcrumb">
                    <li><a href="/admin">首页</a></li>
                    <li><a href="/admin/article">内容管理</a></li>
                    <li><a href="/admin/apage">单页管理</a></li>
                    <li class="active">编辑单页内容</li>
                </ol>
            </div>

            <div class="row clearfix">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="card">
                        <div class="header">
                            <h2> {{$apage->apage_title}} </h2>
                            <ul class="header-dropdown m-r--5">
                                <a href="{{ url()->previous() }}" title="返回上一页"> <i
                                            class="material-icons">arrow_back</i>
                                </a>

                                </li>
                            </ul>
                        </div>
                        <div class="body">


                            <form method="POST" action="">
                                <input type="hidden"  value="{{$apage->apage_id}}" name="apage_id">
                                {{ csrf_field() }}
                                <label for="apage_title">标题</label>
                                <div class="form-group">
                                    <div class="form-line">
                                        <input type="text" id="apage_title" class="form-control" name="apage_title" maxlength="150" value="{{$apage->apage_title}}">
                                    </div>
                                    @if ($errors->has('apage_title'))
                                        <label id="name-error" class="error" for="apage_title">{{ $errors->first('apage_title') }}</label>
                                    @endif

                                </div>
                                <label class="control-label" for="apage_keyword">关键字</label>
                                <div class="form-group ">
                                    <div class="form-line">
                                        <input type="text" id="apage_keyword" class="form-control" name="apage_keyword" value="{{$apage->apage_keyword}}" maxlength="150">
                                    </div>
                                </div>
                                <label class="control-label" for="apage_abstract">摘要</label>
                                <div class="form-group ">
                                    <div class="form-line">
                                        <textarea id="apage_abstract" class="form-control" name="apage_abstract" rows="3" aria-required="true"> {{$apage->apage_abstract}}</textarea>
                                    </div>
                                </div>
                                <label for="exampleInputFile">封面</label>
                                <div class="form-group">
                                    <div class="col-md-3">
                                        <span class="thumbnail apage_image_div">
                                        @if ($apage->apage_image)
                                                <img src="{{$apage->apage_image}}"/>
                                        @endif
                                        </span>
                                    </div>
                                    <div class="col-md-3">

                                    </div>
                                    <div class="col-md-6">

                                        <div style="position: relative; position: relative;margin-top: -59px;">
                                            <a class="btn btn-raised btn-success waves-effect" href="javascript:void(0);">
                                                <i class="material-icons">touch_app</i>
                                            </a>
                                            <input type="file" name="tempfile"
                                                   style="opacity: 0;width:100%;height: 30px;" id="InputFile">
                                            <div class="form-group" >
                                                <span class="label label-info">支持png,jpg,gif等格式</span> <span
                                                        class="label label-warning">文件名不能为汉字</span>
                                            </div>
                                        </div>
                                    </div>
                                    <input type="hidden" id="apage_image" class="apage_image" name="apage_image" value="{{$apage->apage_image}}">
                                </div>

                                <div class="row clearfix"></div>
                                <label class="control-label" for="content">内容</label>
                                <div class="form-group">
                                    <textarea id="apage_content" class="form-control" name="apage_content">{{$apage->apage_content}}</textarea>

                                    @if ($errors->has('apage_content'))
                                        <label id="name-error" class="error" for="apage_content">{{ $errors->first('apage_content') }}</label>
                                    @endif
                                </div>
                                <label  for="apage_views">阅读量</label>
                                <div class="form-group">
                                    <div class="form-line">
                                    <input type="text" id="apage_views" class="form-control" value="{{$apage->apage_views}}" name="apage_views">
                                    </div>
                                </div>
                                <label  for="apage_publish_time">发布时间</label>
                                <div class="form-group">
                                    <div class="form-line">
                                    <input type="text" id="apage_publish_time" class="form-control" value="{{date("Y-m-d H:i:s",$apage->apage_publish_time)}}" name="apage_publish_time">
                                    </div>
                                </div>

                                <div class="hidden-print">
                                    <div class="pull-right">

                                        <button type="reset" class="btn  btn-raised bg-grey waves-effect">重置内容</button>
                                        <button type="submit" class="btn  btn-raised btn-success waves-effect">更新单页
                                        </button>

                                    </div>
                                </div>

                            </form>
                        </div>
                    </div>
                </div>


            </div>
        </div>
    </section>

@endsection
@push('header-css')
    <link href="{{ asset('assets/plugins/redactor2/redactor.css') }}" rel="stylesheet">
@endpush

@push('scripts')
   <script type="text/javascript" charset="utf-8" src="{{ asset('assets/plugins/redactor2/redactor.min.js')}}"></script>

   <script type="application/javascript">
        $(function ($) {

            $('#apage_content').redactor({
                plugins:['source','table','fontcolor','fontsize','inlinestyle','fullscreen'],
                buttons: ['format', 'bold', 'italic', 'deleted', 'lists', 'image', 'file', 'link', 'horizontalrule' ,'horizontalrule', 'underline', 'ol', 'ul', 'indent', 'outdent'], // +
                minHeight: "300px",
                maxHeight: "500px",
                imageUploadParam:'imageFile',
                fileUploadParam:'imageFile',
                imageUpload: '{{Route('admin.upload.images')}}',
                placeholder: '请输入内容.....',
                X_CSRF_TOKEN:'{{csrf_token()}}',
            });


            $('#InputFile').change(function () {
                var File_Data = new FormData();
                File_Data.append('imageFile', $("#InputFile")[0].files[0]);
                File_Data.append('resize', 'true');
                $.ajax({
                    data: File_Data,
                    type: "POST",
                    url: "{{Route('admin.upload.images')}}",
                    cache: false,
                    contentType: false,
                    processData: false,
                    dataType: "json",
                    beforeSend: function (xhr) {
                        xhr.setRequestHeader("X-CSRF-TOKEN", "{{csrf_token()}}");
                    },
                    success: function (ret) {
                        if (ret.error == true) {
                            alert(ret.message);
                        } else {
                            $('.apage_image').val(ret.url);
                            $('#InputFile').val('');
                            $('.apage_image_div').html("<img src='" + ret.url + "' data-id='" + ret.id + "'   />");
                        }
                        console.log(ret);
                    }
                });
            });
        });
    </script>
@endpush